package b_thread;


/**
 * @author Cheng-02
 * @version V1.0
 * @Package b_thread
 * @date 2024/4/6 19:33
 */
public class test02 {
    public static void main(String[] args) {
        MyThread t1 = new MyThread();
        MyThread t2 = new MyThread();
        t1.setName("张三");//设置线程名称
        t2.setName("李四");
        t2.start();
        t1.start();
        System.out.println(Thread.currentThread().getName());//获取当前线程名称

    }
}

class MyThread extends Thread {
    public void run() {
        try {

            for (int i = 0; i < 100; i++) {
                Thread.sleep(2000);
                System.out.println(getName() + "执行了：" + i);
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

    }
}